﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace AdoNet
{
    class ExtractProducts
    {
        static void Main(string[] args)
        {
            SqlConnection dbCon = new SqlConnection(
              "Server=.\\SQLEXPRESS; " +
              "Database=Northwind; " +
              "Integrated Security=true");
            dbCon.Open();
            using (dbCon)
            {
                SqlCommand cqlCom = new SqlCommand("SELECT c.CategoryName as Categorie , p.ProductName as Product "+ 
                    "FROM Products p "+
                    "JOIN Categories c ON c.CategoryID = p.CategoryID "+
                    "order by c.CategoryName", dbCon);
                SqlDataReader reader = cqlCom.ExecuteReader();
                using (reader) 
                {
                    while (reader.Read()) 
                    {
                        Console.WriteLine("Categorie: {0}, product: {1}", reader["Categorie"], reader["Product"]);
                    }
                }
            }

        }
    }
}
